home *** CD-ROM | disk | FTP | other *** search
- (*----------------------------------------------------------------------*)
- (* Send_Ascii_File --- Upload ASCII file *)
- (*----------------------------------------------------------------------*)
-
- OVERLAY PROCEDURE Send_Ascii_File;
-
- (*----------------------------------------------------------------------*)
- (* *)
- (* Procedure: Send_Ascii_File *)
- (* *)
- (* Purpose: Uploads ASCII file to remote host *)
- (* *)
- (* Calling Sequence: *)
- (* *)
- (* Send_Ascii_File; *)
- (* *)
- (* Calls: KeyPressed *)
- (* Async_Send_String *)
- (* Async_Receive *)
- (* *)
- (*----------------------------------------------------------------------*)
-
- CONST
- Pacing_Delay = 0.35 (* Approx. time added per line for pacing *);
- Modem_Fudge = 0.85 (* Approx. fudge factor for timing *);
-
- VAR
- Ch : CHAR;
- Fin : BOOLEAN;
- TextLine : AnyStr;
- Esc_Found : BOOLEAN;
- B : BOOLEAN;
- Pace_Found : BOOLEAN;
- Line_Count : REAL;
- Byte_Count : REAL;
- Time_To_Send : REAL;
- Length_Line : REAL;
- R_Baud_Rate : REAL;
- AFile_Byte : FILE OF BYTE;
- Start_Time : REAL;
- TLine_Delay : REAL;
- Pacing : BOOLEAN;
- I : INTEGER;
-
- (*----------------------------------------------------------------------*)
- (* Update_Ascii_Send_Display --- Update display of Ascii upload *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Update_Ascii_Send_Display;
-
- BEGIN (* Update_Ascii_Send_Display *)
-
- GoToXY( 26 , 5 );
- WRITE( Line_Count:8:0 );
- GoToXY( 26 , 6 );
- WRITE( Byte_Count:8:0 );
- GoToXY( 26 , 7 );
- WRITE( TimeString( Time_To_Send ) );
-
- END (* Update_Ascii_Send_Display *);
-
- (*----------------------------------------------------------------------*)
-
- BEGIN (* Send_Ascii_File *)
-
- (* Open display window for transfer *)
- Save_Screen( Saved_Screen );
-
- Draw_Menu_Frame( 15, 10, 78, 21, Menu_Frame_Color,
- Menu_Text_Color,
- 'Send file ' + FileName + ' using ASCII' );
-
- (* Figure transfer time *)
- Window( 16, 11, 77, 20 );
-
- ASSIGN( Afile_Byte , FileName );
- RESET ( Afile_Byte );
-
- R_Baud_Rate := ( Baud_Rate * Modem_Fudge ) / 10.0;
- Byte_Count := LongFileSize( Afile_Byte );
- Line_Count := 0;
-
- CLOSE( Afile_Byte );
- (* Read file and find # of lines *)
- WRITELN;
- WRITELN(' Scanning ',FileName,' for line count');
-
- ASSIGN( Afile , FileName );
- RESET ( Afile );
-
- REPEAT
- READLN( Afile );
- Line_Count := Line_Count + 1;
- UNTIL( EOF( Afile ) );
-
- RESET( Afile );
- (* Figure approximate transfer time *)
-
- Time_To_Send := Byte_Count / R_Baud_Rate + Char_Delay * Byte_Count +
- Line_Delay * Line_Count;
-
- TLine_Delay := Line_Delay;
-
- IF ( Char_Delay = 0 ) AND
- ( Line_Delay = 0 ) AND
- ( Pacing_Char <> CHR( NUL ) ) THEN
- BEGIN
- Time_To_Send := Time_To_Send + Line_Count * Pacing_Delay;
- TLine_Delay := TLine_Delay + Pacing_Delay;
- END;
-
- Clear_Window;
-
- WRITELN(' Characters to send : ', Byte_Count:8:0 );
- WRITELN(' Lines to send : ', Line_Count:8:0 );
- WRITELN(' Approx. transfer time : ', TimeString( Time_To_Send ) );
- WRITELN(' ');
- WRITELN(' Sending line : ');
- WRITELN(' Bytes left to send : ');
- WRITELN(' Approx. time left : ', TimeString( Time_To_Send ) );
-
- (* Reset line count *)
- Line_Count := 0;
- (* FIN is true when upload complete *)
- Fin := FALSE;
- (* Remember starting time *)
- Start_Time := TimeOfDay;
- (* Flag if pacing char found: *)
- (* assumed TRUE to start things off *)
- Pace_Found := TRUE;
- Pacing := FALSE;
- (* Loop over lines in file *)
- REPEAT
- (* Look if carrier dropped *)
-
- Fin := Fin OR Async_Carrier_Drop;
-
- (* Check buffer status, allow drain if *)
- (* too full. *)
- Async_Buffer_Full;
- (* READ a line from the file to upload *)
- READLN( AFile , TextLine );
- TextLine := TextLine + CR_LF_String;
- Length_Line := LENGTH( TextLine ) + 1;
-
- (* If pacing character specified, wait *)
- (* for it to show up from com port *)
- Esc_Found := FALSE;
-
- IF ( Pacing AND ( NOT Fin ) ) THEN
- REPEAT
- IF KeyPressed THEN
- BEGIN
- READ( Kbd, Ch );
- IF Ch = CHR( ESC ) THEN
- Esc_Found := TRUE
- ELSE
- Async_Send( Ch );
- END;
- IF Async_Buffer_Check THEN
- BEGIN
- B := Async_Receive( Ch );
- Pace_Found := ( Ch = Pacing_Char );
- END;
- UNTIL ( Pace_Found OR Esc_Found )
- ELSE
- REPEAT
- IF KeyPressed THEN
- BEGIN
- READ( Kbd, Ch );
- IF Ch = CHR( ESC ) THEN
- Esc_Found := TRUE
- ELSE
- Async_Send( Ch );
- END;
- IF Async_Buffer_Check THEN
- B := Async_Receive( Ch );
- UNTIL ( Pace_Found OR Esc_Found );
-
- (* Check if Alt-S hit again -- *)
- (* end transfer if so. *)
-
- IF ( Esc_Found AND KeyPressed ) THEN
- BEGIN
- READ( Kbd , Ch );
- IF ORD( Ch ) = Alt_S THEN
- Fin := TRUE
- ELSE
- BEGIN
- Async_Send( CHR( ESC ) );
- Async_Send( Ch );
- END;
- END
- ELSE
- WHILE KeyPressed DO
- BEGIN
- READ( Kbd, Ch );
- Async_Send( Ch );
- END;
- (* Send the next line to the host *)
-
- IF ( NOT Fin ) THEN
- Async_Send_String_With_Delays( TextLine, Char_Delay, Line_Delay );
-
- (* Update status display *)
-
- Line_Count := Line_Count + 1;
-
- Byte_Count := Byte_Count - Length_Line;
- IF Byte_Count < 0.0 THEN
- Byte_Count := 0.0;
-
- Time_To_Send := Time_To_Send - ( Length_Line / R_Baud_Rate )
- - ( Length_Line * Char_Delay )
- - TLine_Delay ;
- IF Time_To_Send <= 0.0 THEN
- Time_To_Send := 0.0;
-
- Update_Ascii_Send_Display;
- (* Ensure pacing if needed after *)
- (* first block *)
-
- Pacing := Pacing_Char <> CHR( NUL );
-
- UNTIL ( Fin OR EOF( AFile ) );
-
- (* Wait for buffer to drain *)
- Async_Purge_Buffer;
-
- GoToXY( 1 , 9 );
-
- IF ( NOT Fin ) THEN
- BEGIN
- Writelne(' Finished sending Ascii file ' + FileName , TRUE );
- GoToXY( 1 , 10 );
- WRITE (' Actual transfer time was ',
- TimeString( TimeDiff( Start_Time, TimeOfDay ) ) );
- END
- ELSE
- Writelne(' Transfer cancelled' , TRUE );
-
- DELAY ( Two_Second_Delay );
-
- CLOSE( AFile );
- (* Remove this window *)
- Restore_Screen( Saved_Screen );
-
- Reset_Global_Colors;
-
- END (* Send_Ascii_File *);